# -*- coding:utf-8 -*-

import os
from selenium import webdriver
from selenium.webdriver.common.by import By

class GetListValue:

    def getListValue(self,driver,tableXpath=None):

        self.driver=driver

        if tableXpath is None:
            tableXpath = "/html/body/content/div/form/div/div[14]"

        self.listul = []
        objul = self.driver.find_elements(By.XPATH,tableXpath + "/ul")

        for countul in range(0,len(objul)):
            listli=[]
            objli = self.driver.find_elements(By.XPATH, tableXpath + "/ul")[countul].find_elements(By.TAG_NAME, "li")

            for countli in range(0,len(objli)):
                listli.append(objli[countli].text)
            self.listul.append(listli)
        # print(listul)

    def clicklistvalue(self,name,bdctype=None):
        for value in range(0,len(self.listul)):
            if self.listul[value][0]==name:
                self.driver.find_element_by_xpath(u"(//a[contains(text(),'查看详情')])[" + str(value) + "]").click()
            # if self.listul[value][2]==name and self.listul[value][5]==bdctype:
            #     driver.find_element_by_xpath(u"(//a[contains(text(),'查看详情')])["+str(value)+"]").click()

    def clickvalue(self,driver,tableXpath,caseno):
        objul = driver.find_elements(By.XPATH,tableXpath + "/ul")

        for countul in range(0,len(objul)-1):
            objli = driver.find_elements(By.XPATH, tableXpath + "/ul")[countul].find_elements(By.TAG_NAME, "li")
            if objli[0].text == caseno :
                for countli in range(0,len(objli)):
                    if objli[countli].text=="查看详情":
                        driver.find_element_by_xpath(tableXpath + "/ul["+str(countul+1)+"]/li["+str(countli+1)+"]/a").click()


if __name__ == "__main__":
    # self.driver = webdriver.Firefox()

    iedriver = "..\\IEDriverServer.exe"
    os.environ["webdriver.ie.driver"] = iedriver
    driver = webdriver.Ie(executable_path=iedriver)

    driver.maximize_window()
    driver.implicitly_wait(10)
    base_url = "http://192.168.200.248:8080"
    verificationErrors = []
    accept_next_alert = True

    driver.get(base_url + "/RealestateTrade")
    driver.get(base_url + "/RealestateTrade")
    driver.find_element_by_id("username").clear()
    driver.find_element_by_id("username").send_keys("gt")
    driver.find_element_by_id("userpwd").clear()
    driver.find_element_by_id("userpwd").send_keys("123")
    ss = driver.find_element_by_id("code").get_attribute("value")
    driver.find_element_by_id("checkCode").clear()
    driver.find_element_by_id("checkCode").send_keys(ss)
    driver.find_element_by_class_name("login-btn").click()

    driver.find_element_by_xpath("/html/body/header/div[2]/ul[1]/li[3]/a/img").click()
    # glv = GetListValue()
    # glv.clickvalue(driver,"/html/body/content/div/form/div/div[19]","20160709000015")

    from AutoTestBDC.extScript.SeaValue import SeaValue
    qlrtype = "其他组织"
    caseno = "20160705000037"
    SeaValue(driver, caseno, qlrtype)
    glv = GetListValue()

    if qlrtype == "自然人":
        tablexpath = "/html/body/content/div/form/div/div[19]"
    elif qlrtype == "法人机构":
        tablexpath = "/html/body/content/div/form/div/div[20]"
    elif qlrtype == "其他组织":
        tablexpath = "/html/body/content/div/form/div/div[21]"

    glv.clickvalue(driver, tablexpath, "20160705000037")

